import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/tour_info";

export const items_api = (showError = true) => {
  return Http.get<MiniApp.PagingData>(`/v1${baseUrl}/items`).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const get_identity_type_list_api = (showError = true) => {
  return Http.get<{ identity_type: any[] }>(
    `/v1${baseUrl}/get_identity_type_list`
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const add_api = (data: any, showError = true) => {
  return Http.post(`/v1${baseUrl}/add`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const del_api = (data: { id: string }, showError = true) => {
  return Http.post(`/v1${baseUrl}/del`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const info_api = (data: { id: string }, showError = true) => {
  return Http.get<any>(`/v1${baseUrl}/info`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
